﻿<!DOCTYPE>
<html ng-app="demoApp">
<head>
    <title id='Description'>AngularJS Chart line series with conditional colors</title>
   <meta name="description" content="This is an example of AngularJS Chart. Chart lines with conditional colors." />
    <link rel="stylesheet" type="text/css" href="../../../jqwidgets/styles/jqx.base.css" />
    <script type="text/javascript" src="../../../scripts/angular.min.js"></script> <script type="text/javascript" src="../../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdraw.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxchart.core.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script>
    <script type="text/javascript">
        var demoApp = angular.module("demoApp", ["jqwidgets"]);
        demoApp.controller("demoController", function ($scope) {
            var source =
            {
                datatype: "csv",
                datafields: [
                    { name: 'Quarter' },
                    { name: 'Change' }
                ],
                url: '../../sampledata/us_gdp_2008-2013.csv'
            };

            var dataAdapter = new $.jqx.dataAdapter(
                source,
                {
                    async: false,
                    autoBind: true,
                    loadError: function (xhr, status, error) {
                        alert('Error loading "' + source.url + '" : ' + error);
                    }
                }
            );

            settings = {
                title: "U.S. GDP Percentage Change",
                borderLineWidth: 1,
                showBorderLine: true,
                enableAnimations: true,
                description: '(source: Bureau of Economic Analysis)',
                showLegend: false,
                padding: { left: 5, top: 5, right: 10, bottom: 5 },
                titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },
                source: dataAdapter,
                categoryAxis:
                {
                    //description: 'Year and quarter',
                    dataField: 'Quarter',
                    unitInterval: 1,
                    textRotationAngle: -75,
                    formatFunction: function (value, itemIndex, serie, group) {
                        return value;
                    },
                    valuesOnTicks: false
                },
                colorScheme: 'scheme05',
                seriesGroups:
                [
                    {
                        type: 'line',
                        valueAxis:
                        {
                            description: 'Percentage Change',
                            formatFunction: function (value) {
                                return value + '%';
                            }
                        },
                        series:
						    [
                                {
                                    dataField: 'Change',
                                    displayText: 'Change',

                                    // Modify this function to return desired colors.
                                    // jqxChart will call the function for each data point.
                                    // Sequential points that have the same color will be
                                    // grouped automatically in a line segment
                                    colorFunction: function (value, itemIndex, serie, group) {
                                        return (value < 0) ? '#FF0000' : '#00FF00';
                                    }
                                }
                            ]
                    }

                ]
            };

            $scope.chartSettings = settings;
        });
    </script>
</head>
<body ng-controller="demoController">
    <jqx-chart id='chartContainer' jqx-settings="chartSettings" style="width: 850px; height: 500px"></jqx-chart>
</body>
</html>
